﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using VisualAgile.DTO;
using VisualAgile.Web.Tests.Fakes;
using System.Collections;
using System.Web;
using VisualAgile.Controllers;
using System.Web.Mvc;
using System.Web.Routing;
using System.Security.Principal;

namespace VisualAgile.Web.Tests
{
    /// <summary>
    /// Summary description for BaseControllerTests
    /// </summary>    
    public class BaseControllerTests
    {
        //public static Controller GetController()
        //{
        //    Controller controller = new BaseController();
        //    ControllerContext controllerContext = new ControllerContext(new MockHttpContext(), new RouteData(), controller);
        //    controller.ControllerContext = controllerContext;
        //    return controller;
        //}

        public class MockHttpContext : HttpContextBase
        {
            private IDictionary _items;
            private IPrincipal _user;                  

            public override IPrincipal User
            {
                get
                {
                    if (_user == null)
                    {
                        _user = FakeUserData.AuthenticatedUser();
                    }
                    return _user;
                }
                set
                {
                    _user = value;
                }
            }

            public override HttpSessionStateBase Session
            {
                get
                {
                    return null;
                }
            }

            public override IDictionary Items
            {
                get
                {
                    if (_items == null)
                    {
                        AllManagerFactory manager = new AllManagerFactory()
                        {
                            UserManager = new FakeUserManager(
                                FakeUserData.CreateTestUsers()
                            ),
                            ProjectManager = new FakeProjectManager(
                                FakeProjectData.CreateTestProjects()
                            ),
                            RoleManager = new FakeRoleManager(
                                FakeRoleData.CreateTestRoles()
                            ),
                            ActualsManager = new FakeActualManager(
                                FakeActualData.CreateTestActual()
                            ),
                            FeatureManager = new FakeFeatureManager(
                                FakeFeatureData.CreateTestFeatures()
                            ),
                            FeelingManager = new FakeFeelingsManager(
                                FakeFeelingsData.CreateTestFeelingss()
                            ),
                            IterationManager = new FakeIterationManager(
                                FakeIterationData.CreateTestIterations()
                            ),
                            LabelManager = new FakeLabelManager(
                                FakeLabelData.CreateDemoLabels()
                            ),
                            ReleaseManager = new FakeReleaseManager(
                                FakeReleaseData.CreateTestReleases()
                            ),
                            StatusManager = new FakeStatusManager(
                                FakeStatusData.CreateTestStatuss()
                            ),
                            StoryManager = new FakeStoryManager(
                                FakeStoryData.CreateTestStorys()
                            ),
                            TaskManager = new FakeTaskManager(
                                FakeTaskData.CreateTestTasks()
                            )
                        };

                        _items = new Dictionary<string, AllManagerFactory>();
                        _items.Add("ManagerFactory", manager);
                    }

                    return _items;
                }
            }
        }
    }
}
